package com.dayatang.android.Activity;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.view.Menu;

import com.dayatang.android.Util.BitmapUtil;
import com.dayatang.android.map.PersonLocationOverItem;
import com.google.android.maps.GeoPoint;

public class PersonLocationActivity extends MapBaseActivity {
	
	protected void InitData() {
		try {
			String url = getServerAddress() + "/remote/person-location.action?username=" + getUsername();
			String data = getDataByUrl(url);
			if (data != null) {
				JSONArray jsonArray = new JSONArray(data);
				for (int i = 0 , len = jsonArray.length(); i < len; i++) { 
					JSONObject jsonObject = jsonArray.getJSONObject(i); 
					GeoPoint geoPoint = new GeoPoint((int)(jsonObject.getDouble("latitude")*1E6),(int)(jsonObject.getDouble("longitude")*1E6));
					mapController.setZoom(13);
					mapController.animateTo(geoPoint);
					List<GeoPoint> list = new ArrayList<GeoPoint>();
					list.add(geoPoint);
					Drawable marker = BitmapUtil.drawPersonName(getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.alert2), this, jsonObject.getString("name")); 
					marker.setBounds(0, 0, marker.getIntrinsicWidth(), marker.getIntrinsicHeight());   //为maker定义位置和边界
					overlays.add(new PersonLocationOverItem(marker,this,list));
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
			ToastShow(getString(R.string.software_error));
		}
	}
	
    public boolean onCreateOptionsMenu(Menu menu) {
		return false;
    }

}
